//
//  LYSearchBar.swift
//  微博
//
//  Created by liuerying on 16/5/19.
//  Copyright © 2016年 liuerying. All rights reserved.
//

import UIKit

class LYSearchBar: UIView {

    //文本框
    @IBOutlet weak var searchTF: UITextField!
    
    //textF的右边约束线
    @IBOutlet weak var rightCon: NSLayoutConstraint!

    //搜索按钮
    @IBOutlet weak var cancleBtn: UIButton!
    
    @IBAction func cancleBtnClick(sender: AnyObject) {
        
        self.rightCon.constant = 0
        UIView.animateWithDuration(0.25) {
            
            
            self.layoutIfNeeded()
        }
        
        self.endEditing(true)
    }


    //点击textF的事件
    @IBAction func searchTF(sender: AnyObject) {
        UIView.animateWithDuration(0.25) { 
            
            self.rightCon.constant = self.cancleBtn.bounds.width
            
            self.layoutIfNeeded()
        }
        
        
    }
    
    //对外提供的类方法-- 加载xib
   class func loadsearchBtn()->LYSearchBar{
    
    
    let searchView = NSBundle.mainBundle().loadNibNamed("HMSearchBar", owner: nil, options: nil).last as! LYSearchBar
    
        return searchView

    }
    
    
    override func awakeFromNib() {
        
        self.bounds.size.width = ScreeWidth
        
        searchTF.leftView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        
        searchTF.leftViewMode = .Always
        
        searchTF.leftView?.frame = CGRect(x: 0, y: 0, width: 50, height: 40)
        searchTF.leftView?.contentMode = .Center
        
        //切圆角
        searchTF.layer.cornerRadius = 20
       searchTF.layer.masksToBounds = true
        
        //设置边框线
       searchTF.layer.borderColor = UIColor.orangeColor().CGColor
        searchTF.layer.borderWidth = 1
        
        
    }
    
    
    
}
